Skip to content

Avoid final field modification in JUnit5 instrumentation#11752

Open
daniel-mohedano wants to merge 1 commit into
masterfrom
daniel.mohedano/jep-500-junit
Open

Avoid final field modification in JUnit5 instrumentation#11752
daniel-mohedano wants to merge 1 commit into
masterfrom
daniel.mohedano/jep-500-junit

Conversation

@daniel-mohedano

@daniel-mohedano daniel-mohedano commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

  • Avoids final field modifications in JUnit5 instrumentation by:
    • Building a fresh TestTask for every retry, reusing the original parent context, instead of reusing and modifying the original test task. This approach is only supported for versions 5.3.1+.
    • Introducing a new TestDescriptor cloning method based on JupiterTestDescriptor#copyIncludingDescendants(UnaryOperator<UniqueId>)}, which also avoids manually setting the generated uniqueId after the cloning. This approach is only supported for versions 5.13+.

Motivation

Avoid failures in future JDKs due to JEP 500: Prepare to Make Final Mean Final.

Additional Notes

Running an example project on JDK26 with JAVA_TOOL_OPTIONS=--illegal-final-field-mutation=debug produced the following logs:

Final field testDescriptor in class org.junit.platform.engine.support.hierarchical.NodeTestTask has been unreflected for mutation ...
Final field node in class org.junit.platform.engine.support.hierarchical.NodeTestTask has been unreflected for mutation ...
Final field uniqueId in class org.junit.platform.engine.support.descriptor.AbstractTestDescriptor has been unreflected for mutation ...
Final field interceptorCall in class org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor has been mutated reflectively ...
Final field methodInfo in class org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor has been mutated reflectively ...
Final field configuration in class org.junit.jupiter.engine.descriptor.JupiterTestDescriptor has been mutated reflectively ...
...

The build containing the fix doesn't produce the logs.

Contributor Checklist

  • Format the title according to the contribution guidelines
  • Assign the type: and (comp: or inst:) labels in addition to any other useful labels
  • Avoid using close, fix, or any linking keywords when referencing an issue
    Use solves instead, and assign the PR milestone to the issue
  • Update the CODEOWNERS file on source file addition, migration, or deletion
  • Update public documentation with any new configuration flags or behaviors
  • Add your completed PR to the merge queue by commenting /merge. You can also:
    • Customize the commit message associated with the merge with /merge --commit-message "..."
    • Remove your PR from the merge queue with /merge -c
    • Skip all merge queue checks with /merge -f --reason "reason"; please use this judiciously, as some checks do not run at the PR-level (note: the PR still needs to be mergeable, this will only skip the pre-merge build)
    • Get more information in this doc

Jira ticket: SDTEST-3867

@daniel-mohedano daniel-mohedano added type: enhancement Enhancements and improvements comp: ci visibility Continuous Integration Visibility labels Jun 26, 2026
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - sbt-scalatest

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent 56.69 54.33 $\color{red}{\blacktriangle}$ +2.36 55.43 $\color{red}{\blacktriangle}$ +1.26 46/188
agentEvpProxy 55.01 n/a n/a n/a n/a -

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - nebula-release-plugin

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent 37.55 36.42 $\color{red}{\blacktriangle}$ +1.13 36.42 $\color{red}{\blacktriangle}$ +1.13 23/91
agentless 37.69 35.70 $\color{red}{\blacktriangle}$ +1.99 35.70 $\color{red}{\blacktriangle}$ +1.99 23/91
agentlessCodeCoverage 44.57 44.48 $\color{red}{\blacktriangle}$ +0.09 44.48 $\color{red}{\blacktriangle}$ +0.09 23/91
agentlessLineCoverage 76.92 74.82 $\color{red}{\blacktriangle}$ +2.10 74.82 $\color{red}{\blacktriangle}$ +2.10 22/90

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - netflix-zuul

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent 87.88 86.07 $\color{red}{\blacktriangle}$ +1.81 86.07 $\color{red}{\blacktriangle}$ +1.81 24/130
agentless 81.38 81.05 $\color{red}{\blacktriangle}$ +0.33 81.05 $\color{red}{\blacktriangle}$ +0.33 23/129
agentlessCodeCoverage 96.01 95.12 $\color{red}{\blacktriangle}$ +0.89 95.12 $\color{red}{\blacktriangle}$ +0.89 23/127
agentlessLineCoverage 111.63 111.62 $\color{red}{\blacktriangle}$ +0.01 111.62 $\color{red}{\blacktriangle}$ +0.01 22/126

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - pass4s

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent 15.39 9.92 $\color{red}{\blacktriangle}$ +5.47 9.92 $\color{red}{\blacktriangle}$ +5.47 24/94
agentless 11.90 10.13 $\color{red}{\blacktriangle}$ +1.77 9.92 $\color{red}{\blacktriangle}$ +1.98 24/95
agentlessCodeCoverage 18.25 17.03 $\color{red}{\blacktriangle}$ +1.22 17.73 $\color{red}{\blacktriangle}$ +0.52 22/93

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - reactive-streams-jvm

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent 19.69 21.65 $\color{green}{\blacktriangledown}$ -1.96 21.65 $\color{green}{\blacktriangledown}$ -1.96 26/143
agentless 17.38 18.82 $\color{green}{\blacktriangledown}$ -1.44 18.82 $\color{green}{\blacktriangledown}$ -1.44 25/140
agentlessCodeCoverage 18.13 19.59 $\color{green}{\blacktriangledown}$ -1.46 19.99 $\color{green}{\blacktriangledown}$ -1.86 25/140
agentlessLineCoverage 28.07 29.82 $\color{green}{\blacktriangledown}$ -1.75 29.82 $\color{green}{\blacktriangledown}$ -1.75 24/140

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - jolokia

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent 91.25 93.23 $\color{green}{\blacktriangledown}$ -1.98 93.23 $\color{green}{\blacktriangledown}$ -1.98 27/96
agentless 86.66 89.58 $\color{green}{\blacktriangledown}$ -2.92 89.58 $\color{green}{\blacktriangledown}$ -2.92 26/96
agentlessCodeCoverage 96.15 99.00 $\color{green}{\blacktriangledown}$ -2.85 99.00 $\color{green}{\blacktriangledown}$ -2.85 23/93
agentlessLineCoverage 98.49 99.00 $\color{green}{\blacktriangledown}$ -0.51 99.00 $\color{green}{\blacktriangledown}$ -0.51 23/93

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - okhttp

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent 17.94 19.20 $\color{green}{\blacktriangledown}$ -1.26 19.59 $\color{green}{\blacktriangledown}$ -1.65 26/96
agentless 19.33 18.82 $\color{red}{\blacktriangle}$ +0.51 19.20 $\color{red}{\blacktriangle}$ +0.13 25/98
agentlessCodeCoverage 23.41 22.09 $\color{red}{\blacktriangle}$ +1.32 22.09 $\color{red}{\blacktriangle}$ +1.32 25/94
agentlessLineCoverage 44.67 44.48 $\color{red}{\blacktriangle}$ +0.19 44.48 $\color{red}{\blacktriangle}$ +0.19 28/97

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Test Environment - sonar-java

Job Status: 🟢 success

Scenario This PR (%) 7d median Δ 7d 30d median Δ 30d runs (7d/30d)
agent -0.16 24.91 $\color{green}{\blacktriangledown}$ -25.07 16.04 $\color{green}{\blacktriangledown}$ -16.20 26/96
agentless 25.34 19.99 $\color{red}{\blacktriangle}$ +5.35 15.11 $\color{red}{\blacktriangle}$ +10.23 25/95
agentlessCodeCoverage 86.10 95.12 $\color{green}{\blacktriangledown}$ -9.02 87.80 $\color{green}{\blacktriangledown}$ -1.70 25/95
agentlessLineCoverage 95.98 133.64 $\color{green}{\blacktriangledown}$ -37.66 144.77 $\color{green}{\blacktriangledown}$ -48.79 24/94

Baseline: median of @test.tracer_overhead on main (gitlab) over the last 7/30 days, per OSS project & scenario. Δ = this PR − baseline median; red ▲ = more overhead, green ▽ = less overhead than baseline.

@daniel-mohedano daniel-mohedano marked this pull request as ready for review June 29, 2026 14:58
@daniel-mohedano daniel-mohedano requested a review from a team as a code owner June 29, 2026 14:58

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

More details

Three critical correctness invariants hold: (1) ThrowableCollectorFactoryWrapper is installed on NodeTestTaskContext (shared across all retry tasks), so factory.setSuppressFailures() correctly controls each retry even though currentTask is now a fresh NodeTestTask; (2) AbstractTestDescriptor.setParent() only sets the child's parent reference without addChild(), so the snapshot and retry descriptors are not injected into the parent's children list; (3) legacyCopy's new conditional uniqueId setter is correct — tryShallowClone already copies all fields including uniqueId, so the setter is only needed when the ID actually changes.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit c73e0a4 · What is Autotest? · Any feedback? Reach out in #autotest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: ci visibility Continuous Integration Visibility type: enhancement Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants